import axios from 'axios'
export var loginState = {
  // 登陆页面表单数据
  loginPage: {
    login: {
      employeeID: null,
      employeePassword: null
    }
  }
}
export var loginMutations = {
  setCurrentUser (state, data) {
    for (let key in data) {
      state.userInfo[key] = data[key]
    }
    state.userInfo.isLogged = true
  }
}
export var loginActions = {
  checkPassword (context, data) {
    return new Promise((resolve, reject) => {
      axios.post(
        '/api/backCheckPassword',
        data
      )
        .then((response) => {
          if (response.data.length) { // 如果密码正确
            context.commit('setCurrentUser', response.data[0])
          } else {
            resolve(false)
          }
        })
    })
  }
}
